<template>
	<div class="content">
		<Collapse v-model="value1">
			<Panel name="1">
				其他设置
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								广告值市值
								<Input class="w80" v-model.trim="other.advertising.content" /> CNY
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update(other.advertising.id,other.advertising.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								USDT市值
								<Input class="w80" v-model.trim="other.usdt.content" /> CNY
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update(other.usdt.id,other.usdt.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								发送手续费
								<Input class="w80" v-model.trim="other.send.content" /> %
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update(other.send.id,other.send.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								升级广告主
								<Input class="w80" v-model.trim="other.advertiser.content" /> 份
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update(other.advertiser.id,other.advertiser.content)">保　存</Button> &nbsp;
								<span style="color: red;">&nbsp;注：需要购买的订单数量</span>
							</div>
						</div>
					</Form>
				</p>
				<!--<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								提现手续费
								<Input class="w80" v-model.trim="other.transferConfig.content" /> %
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update2(other.transferConfig.id,other.transferConfig.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								提现手续费额度
								<Input class="w80" v-model.trim="other.sommaFissa.content" /> USDT
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update(other.sommaFissa.id,other.sommaFissa.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>-->
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								提现手续费
								<Input class="w80" v-model.trim="other.transferConfig.content" :disabled="!noconfig2"/> %
							</FormItem>
							<FormItem style="margin-left: -60px;">
								每笔固定手续费
								<Input class="w80" v-model.trim="other.sommaFissa.content" :disabled="noconfig2"/> USDT
							</FormItem>
							<FormItem style="margin-left: -60px;">
								<i-switch size="large" v-model.trim="noconfig2" @on-change="switchOpenAndClose">
									<span slot="open">&nbsp;&nbsp;%</span>
									<span slot="close">USDT</span>
								</i-switch>
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update3(other.transferConfig.id,other.transferConfig.content,other.sommaFissa.id,other.sommaFissa.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="">
								最低提现广告值
								<Input class="w80" v-model.trim="other.minimumWithdrawal.content" /> 积分
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="update(other.minimumWithdrawal.id,other.minimumWithdrawal.content)">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
			</Panel>
			<Panel name="2">
				禁止提币
				<p slot="content">
					<Form label-position="right" :label-width="100">
						<div class="canshu">
							<FormItem label="禁止提币：">
								<CheckboxGroup>
									<Checkbox v-model.trim="noconfig"><span>USDT</span></Checkbox>
								</CheckboxGroup>
							</FormItem>
							<div class="p-10">
								<Button type="primary" size="large" v-on:click="sureNoconfig">保　存</Button>
							</div>
						</div>
					</Form>
				</p>
			</Panel>
		</Collapse>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				value1: '1', // 默认展开第一个列表
				noconfig: '', // 查询禁止提币
				noconfig2: '', // 开启和环比
				other: {
					advertiser: '', // 广告值市值
					usdt: '', // USDT 市值
					advertising: '', // 广告主基数
					send: '', // 发送手续费
					transferConfig: '', // 提币手续费
					minimumWithdrawal: '', // 最低提现数量
					sommaFissa: '' // 固定额度手续费
				}
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			});
			this.getOther(); // 其他配置查询
			this.noConfig(); // 查询禁止提币
		},
		methods: {
			getOther() { // 其他配置查询
				let token = localStorage.getItem("mytoken");
				this.axios.get('parameter/back/config', {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.other = res.data.data;
						if(res.data.data.transferOff.content == 1) {
							this.noconfig2 = true;
						} else if(res.data.data.transferOff.content == 2) {
							this.noconfig2 = false;
						}
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			noConfig() { // 查询禁止提币
				let token = localStorage.getItem("mytoken");
				this.axios.get('parameter/forbid/config', {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						if(res.data.data.forbidChargeConfigs[0] == 1) {
							this.noconfig = true;
						} else {
							this.noconfig = false;
						}
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			sureNoconfig() { // 修改禁止提币
				let token = localStorage.getItem("mytoken");
				let noconfig;
				if(this.noconfig != true) {
					noconfig = '';
				} else {
					noconfig = 1;
				}
				let params = this.qs.stringify({
					startList: noconfig,
				})
				this.axios.put('parameter/forbid/config', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.$Message.info(res.data.message);
						this.noConfig();
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			update(index, content) {
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					id: index,
					content: content,
				})
				this.axios.put('parameter/back/config', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.$Message.info(res.data.message);
						this.getOther();
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			update2(index, content) {
				let token = localStorage.getItem("mytoken");
				let params = this.qs.stringify({
					id: index,
					content: content,
				})
				this.axios.put('parameter/transfer/config', params, {
					headers: {
						Authorization: "bearer " + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.$Message.info(res.data.message);
						this.getOther();
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem("mytoken");
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			switchOpenAndClose(index) { // 开启和关闭
				let sureIndex = index;
				let token = localStorage.getItem('mytoken');
				if(index == true){
					sureIndex = 1;
					this.noconfig2 = true;
				}else if(index == false){
					sureIndex = 2;
					this.noconfig = false;
				}
				this.axios.get('parameter/get/transferOff/' + sureIndex, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.getOther();
					} else if(res.data.code == 4004) {
						this.$Message.info(res.data.message);
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message);
						localStorage.removeItem('mytoken');
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			update3(transferConfigid,transferConfigcontent,sommaFissaid,sommaFissacontent) { // 混合传值
				/**get/advPoolOff/
				 * transferConfigid 提现手续费 ID
				 * transferConfigcontent 提现手续费内容
				 * sommaFissaid 提现手续费额度 ID
				 * sommaFissacontent 提现手续费额度内容
				 */
				let token = localStorage.getItem("mytoken");
				if(this.other.transferOff.content == 1){
					let params = this.qs.stringify({
						id: transferConfigid,
						content: transferConfigcontent,
					})
					this.axios.put('parameter/transfer/config', params, {
						headers: {
							Authorization: "bearer " + token
						}
					}).then(res => {
						if(res.data.code == 8008) {
							this.$Message.info(res.data.message);
							this.getOther();
						} else if(res.data.code == 4004) {
							this.$Message.info(res.data.message);
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message);
							localStorage.removeItem("mytoken");
							this.$router.push({
								name: 'login'
							})
						}
					})
				}else if(this.other.transferOff.content == 2){
					let params = this.qs.stringify({
						id: sommaFissaid,
						content: sommaFissacontent,
					})
					this.axios.put('parameter/back/config', params, {
						headers: {
							Authorization: "bearer " + token
						}
					}).then(res => {
						if(res.data.code == 8008) {
							this.$Message.info(res.data.message);
							this.getOther();
						} else if(res.data.code == 4004) {
							this.$Message.info(res.data.message);
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message);
							localStorage.removeItem("mytoken");
							this.$router.push({
								name: 'login'
							})
						}
					})
				}
				
			}
		}
	}
</script>

<style lang="less" scoped>
	.p-10 {
		padding-top: 0 !important;
		padding-left: 50px !important;
	}
	
	.w50 {
		width: 50px !important;
	}
	
	.mar {
		margin-left: 5px;
	}
</style>